Skip to content

Conversation

@madmike200590
Copy link
Collaborator

@madmike200590 madmike200590 commented Nov 2, 2025

Support for actions and program modularization

  • Adds support for action rules, i.e. rules that call procedures with side-effects (e.g. writing to a file) when firing.
  • Adds support for modules, which enable using ASP-programs as subroutines which can be used in a main program similar to external atoms

Detailed formal semantics for both actions and modules are described in Chapter 3 of [1].

Action Rules

Overview

Action rules allow for so-called side-effects in an ASP program, i.e. when an action rule fires, certain changes (such as opening or writing to files) can be applied to the environment. Consider the following Hello World-style example:

hello_text("Hello World!").
hello_result(R) : @streamWrite[STDOUT, TEXT] = R :- hello_text(TEXT), &stdout(STDOUT).

The rule on line 2 is an action rule:

  • hello_result(R) : @streamWrite[STDOUT, TEXT] = R is an action head, where hello_result(R) is a regular head atom, but @streamWrite[STDOUT, TEXT] = R references an action function that has 2 input terms (variables STDOUT and TEXT) and yields the result term R.
  • When the body of an action rule is considered to be true (i.e. the rule fires), the action function is called.
  • In the example, the action function @streamWrite[STDOUT, TEXT] writes the string TEXT to the file descriptor STDOUT. Variable STDOUT is bound by an external atom &stdout(STDOUT) which always supplies a reference to the standard output stream.

Semantics and Restrictions

To stay in line with ASPs declarative semantics, action rulesin Alpha

  • may only apply their action function to the "outside world" once, regardless of how often the solver internally evaluates the rule. Applied to the hello world example, an implementation needs to make sure Hello World! is only written to the console once, regardless of the solver's actual evaluation strategy.
  • may only occur in programs that are fully stratifiable (in their nonground version, stratifying by predicates as implemented in PR Partial up-front evaluation of stratifiable program parts - issue #75 #207 ). This is to ensure that all action results are part of an answer set so that whenever a side-effect is applied, there is an atom in an answer set "witnessing", i.e. making transparent said side-effect.

Implementation

Rules with action heads are modelled as instances of NormalRule whose head is an instance of ActionHead:

public interface ActionHead extends NormalHead {
	String getActionName();
	List<Term> getActionInputTerms();
	VariableTerm getActionOutputTerm();
}

[1]: https://repositum.tuwien.at/handle/20.500.12708/220293 Michael Langowski. Evolog-Actions and Modularization in Lazy-Grounding Answer Set Programming. Master Thesis, Technische Universität Wien, 2025.

madmike200590 and others added 30 commits January 9, 2024 21:14
…st<Term>> rather than just Set<List<ConstantTerm>> so we can have module interpretations returning function terms
…s interpretations for module literals by wrapping calls to the ASP solver.
…n. Add very simple end2end test with module-based 3-coloring implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants